<?php

class m131104_043448_oak extends CDbMigration
{
	public function safeUp()
	{
        $sql = 'ALTER TABLE `{{photo}}` ADD INDEX idx_user_id (`user_id`);
                ALTER TABLE `{{photo}}` ADD FOREIGN KEY (`user_id`) REFERENCES `{{user}}` (`id`);
                
                ALTER TABLE `{{user}}` ADD INDEX idx_gender_id (`gender_id`);
                ALTER TABLE `{{user}}` ADD FOREIGN KEY (`gender_id`) REFERENCES `{{gender}}` (`id`);
                
                ALTER TABLE `{{user}}` ADD INDEX idx_hometown_id (`hometown_id`);
                ALTER TABLE `{{user}}` ADD FOREIGN KEY (`hometown_id`) REFERENCES `{{location}}` (`id`);
                
                ALTER TABLE `{{user}}` ADD INDEX idx_location_id (`location_id`);
                ALTER TABLE `{{user}}` ADD FOREIGN KEY (`location_id`) REFERENCES `{{location}}` (`id`);
                
                ALTER TABLE `{{user}}` ADD INDEX idx_avatar_id (`avatar_id`);
                ALTER TABLE `{{user}}` ADD FOREIGN KEY (`avatar_id`) REFERENCES `{{photo}}` (`id`);';
        
        $this->execute($sql);
	}
    
    public function safeDown()
    {
        return false;
    }
}